﻿#ifndef GRAPHICSSCENE_H
#define GRAPHICSSCENE_H

#include <QGraphicsScene>

class TetrisItem;
class QTimer;
class QElapsedTimer;
class BlockGroup;
class BlockGroupMove;

class GraphicsScene : public QGraphicsScene
{
    Q_OBJECT
public:
    explicit GraphicsScene(QObject *parent = nullptr);

    void setSpeed(int value);
    void game_start();

signals:

private slots:
    void clear_full_rows();

protected:
    void drawForeground(QPainter *painter, const QRectF &rect);
    void drawBackground(QPainter *painter, const QRectF &rect);

private:
    void scene_init();
    QGraphicsTextItem *set_text(QString text, QPointF pos, QFont font, QColor color = Qt::white);

    QGraphicsTextItem *player_item, *time_item, *score_item;

    QList<TetrisItem*> tetrisList;      //保存的方块组
    int speed;                          //速度（难度）
    QTimer *stand_timer;                //1s钟更新一次时间显示
    QElapsedTimer *elapsedTimer;        //记录游戏时间
    QTimer *game_timer;                 //游戏速度计时器
    void next_block();                  //召唤下一个方块

    BlockGroup *nextBlockGroup;         //下一个方块
    BlockGroupMove *currentBlockGroup;
};

#endif // GRAPHICSSCENE_H
